<?php
include_once dirname(__FILE__).'/inc/common/AliyunVod.php';
	class goouc_classModuleSite extends WeModuleSite{

		public function doWebIndex(){
			global $_W,$_GPC;
			$op = empty($_GPC['op'])?'setting':$_GPC['op'];
			$type = empty($_GPC['type'])?'city':$_GPC['type'];
			$oop = empty($_GPC['oop'])?'list':$_GPC['oop'];
			if($op == 'setting'){
				if($type == 'city'){

					if($oop == 'list'){
						$contion = "weid = :weid";
						$params = array(':weid'=>$_W['uniacid']);

						$citylist = pdo_fetchall("SELECT * FROM ".tablename('goouc_class_city')." WHERE ".$contion." ORDER BY `order` DESC",$params);
					}elseif($oop == 'add'){
						$cityid = $_GPC['cityid'];
						$cityinfo = pdo_fetch('SELECT * FROM '.tablename('goouc_class_city')." WHERE id = :id AND weid = :weid",array(':id'=>$cityid,':weid'=>$_W['uniacid']));
						if($_W['isajax']){
							return json_encode($cityinfo);
						}
						if(checksubmit('submit')){
							$data['name'] = trim($_GPC['name']);
							$data['order'] = intval($_GPC['order']);
							$data['status'] = intval($_GPC['status']);
							$data['description'] = trim($_GPC['description']);
							$data['weid'] = intval($_W['uniacid']);
							$data['addtime'] = time();
							if(empty($data['name'])){
								message('城市名称不能为空','','error');
							}
							if(empty($cityid)){
								$res = pdo_insert('goouc_class_city',$data);
								if($res){
									$arr = array(
										'weid'=>$_W['uniacid'],
										'admin_uid'=>$_W['uid'],
										'admin_username'=>$_W['username'],
										'log_type'=>1,
										'function'=>'基本设置->城市设置',
										'content'=>'新增城市'
									);
									$this->addlog($arr);
								}
							}else{
								$res = pdo_update('goouc_class_city',$data,array('weid'=>$_W['uniacid'],'id'=>$cityid));
								if($res){
									$arr = array(
										'weid'=>$_W['uniacid'],
										'admin_uid'=>$_W['uid'],
										'admin_username'=>$_W['username'],
										'log_type'=>3,
										'function'=>'基本设置->城市设置',
										'content'=>'更改城市信息'
									);
									$this->addlog($arr);
								}
							}
							if($res){
								message('操作成功',$this->createWebUrl('index',array('op'=>'setting','type'=>"city",'oop'=>'list')),'success');
							}else{
								message('操作失败',$this->createWebUrl('index',array('op'=>'setting','type'=>"city",'oop'=>'list')),'error');
							}
						}
					}elseif($oop == 'delete'){
						$id = intval($_GPC['cityid']);
						$num = pdo_fetch("SELECT * FROM ".tablename('goouc_class_teacher')." WHERE cityid = :cityid AND weid = :weid",array(':cityid'=>$id,':weid'=>$_W['uniacid']));
                        $snum = pdo_fetch("SELECT * FROM ".tablename('goouc_class_lesson')." WHERE cityid = :cityid AND weid = :weid",array(':cityid'=>$id,':weid'=>$_W['uniacid']));
						if($num || $snum){
							itoast('该城市下还有老师和课程，不能删除');
						}
						$res = pdo_delete('goouc_class_city',array('weid'=>$_W['uniacid'],'id'=>$id));
						if($res){
							$arr = array(
								'weid'=>$_W['uniacid'],
								'admin_uid'=>$_W['uid'],
								'admin_username'=>$_W['username'],
								'log_type'=>2,
								'function'=>'基本设置->城市设置',
								'content'=>'删除城市'
							);
							$this->addlog($arr);
							message('删除成功',$this->createWebUrl('index',array('op'=>'setting','type'=>'city')),'success');
						}else{
							message('删除失败','','error');
						}
					}elseif($oop == 'info'){
						$cityid = intval($_GPC['cityid']);
						$info = pdo_get("goouc_class_city",array('id'=>$cityid));
						if($_W['ispost']){
							$data['address'] = trim($_GPC['address']);
							$data['tel'] = intval($_GPC['tel']);
							$data['image'] = trim($_GPC['image']);
							$data['description'] = trim($_GPC['description']);
							$data['qq'] = $_GPC['qq'];
							$res = pdo_update('goouc_class_city',$data,array('id'=>$cityid));
							if($res){
								$arr = array(
									'weid'=>$_W['uniacid'],
									'admin_uid'=>$_W['uid'],
									'admin_username'=>$_W['username'],
									'log_type'=>3,
									'function'=>'基本设置->城市设置',
									'content'=>'修改城市设置'
								);
								$this->addlog($arr);
								message('信息填写成功',$this->createWebUrl('index',array('op'=>'setting','type'=>'city')),'success');
							}else{
								message('信息填写失败',$this->createWebUrl('index',array('op'=>'setting','type'=>'city')),'error');
							}
						}
					}elseif($oop == 'changestatus'){
						$id = $_GPC['id'];
						$data['status'] = $_GPC['sta'];
						$info = pdo_get('goouc_class_city',array('id'=>$id,'weid'=>$_W['uniacid']));
						if($data['status'] == $info['status']){
							$message = array('success'=>0,'修改失败，请刷新页面后重新修改');
						}else{
							$res = pdo_update('goouc_class_city',$data,array('id'=>$id,'weid'=>$_W['uniacid']));
							if($res){
								$message = array('success'=>1,'mess'=>'修改成功');
							}else{
								$message = array('success'=>0,'mess'=>'修改失败');
							}
						}
						echo json_encode($message);exit;
					}
				}elseif($type == 'class'){

					if($oop == 'list'){
						$contion = "weid = :weid";
						$params = array(':weid'=>$_W['uniacid']);

						$classlist = pdo_fetchall("SELECT * FROM ".tablename('goouc_class_class')." WHERE ".$contion." ORDER BY `order` DESC",$params);
						$subjectlist =  pdo_fetchall("SELECT * FROM ".tablename('goouc_class_subject')." WHERE ".$contion." ORDER BY `order` DESC",$params);
					}elseif($oop == 'add'){

						$classid = $_GPC['classid'];
						$classinfo = pdo_fetch('SELECT * FROM '.tablename('goouc_class_class')." WHERE id = :id AND weid = :weid",array(':id'=>$classid,':weid'=>$_W['uniacid']));
						$classinfo['subjectid'] = unserialize($classinfo['subjectid']);
						if($_W['isajax']){
							return json_encode($classinfo);
						}


						if(checksubmit('submit')){
							$data['name'] = trim($_GPC['name']);
							$data['order'] = intval($_GPC['order']);
							$data['status'] = intval($_GPC['status']);
							$data['weid'] = intval($_W['uniacid']);
							$data['subjectid'] = trim(serialize($_GPC['subjectid']));
							$data['addtime'] = time();
							$data['classyear'] = $_GPC['classyear'];
							if(empty($data['name'])){
								message('年级不能为空','','error');
							}

							if(empty($classid)){
								$res = pdo_insert('goouc_class_class',$data);
								if($res){

									$arr = array(
										'weid'=>$_W['uniacid'],
										'admin_uid'=>$_W['uid'],
										'admin_username'=>$_W['username'],
										'log_type'=>1,
										'function'=>'基本设置->年级设置',
										'content'=>'新增年级'
									);
									$this->addlog($arr);
								}
							}else{
								$res = pdo_update('goouc_class_class',$data,array('weid'=>$_W['uniacid'],'id'=>$classid));
								if($res){
									$arr = array(
										'weid'=>$_W['uniacid'],
										'admin_uid'=>$_W['uid'],
										'admin_username'=>$_W['username'],
										'log_type'=>3,
										'function'=>'基本设置->年级设置',
										'content'=>'更改年级信息'
									);
									$this->addlog($arr);
								}
							}
							if($res){
								message('操作成功',$this->createWebUrl('index',array('op'=>'setting','type'=>"class",'oop'=>'list')),'success');
							}else{
								message('操作失败',$this->createWebUrl('index',array('op'=>'setting','type'=>"class",'oop'=>'list')),'error');
							}
						}
					}elseif($oop == 'delete'){

						$id = intval($_GPC['classid']);

                        $snum = pdo_fetch("SELECT * FROM ".tablename('goouc_class_lesson')." WHERE classid = :classid AND weid = :weid",array(':classid'=>$id,':weid'=>$_W['uniacid']));
                        if( $snum){
                            itoast('该班级下还有课程，不能删除');
                        }
						$res = pdo_delete('goouc_class_class',array('weid'=>$_W['uniacid'],'id'=>$id));
						if($res){
							$arr = array(
								'weid'=>$_W['uniacid'],
								'admin_uid'=>$_W['uid'],
								'admin_username'=>$_W['username'],
								'log_type'=>2,
								'function'=>'基本设置->年级设置',
								'content'=>'删除年级'
							);
							$this->addlog($arr);
							message('删除成功',$this->createWebUrl('index',array('op'=>'setting','type'=>'class')),'success');
						}else{
							message('删除失败','','error');
						}
					}elseif($oop == 'changestatus'){
						$id = $_GPC['id'];
						$data['status'] = $_GPC['sta'];
						$info = pdo_get('goouc_class_class',array('id'=>$id,'weid'=>$_W['uniacid']));
						if($data['status'] == $info['status']){
							$message = array('success'=>0,'修改失败，请刷新页面后重新修改');
						}else{
							$res = pdo_update('goouc_class_class',$data,array('id'=>$id,'weid'=>$_W['uniacid']));
							if($res){
								$message = array('success'=>1,'mess'=>'修改成功');
							}else{
								$message = array('success'=>0,'mess'=>'修改失败');
							}
						}
						echo json_encode($message);exit;
					}
				}elseif($type == 'subject'){

					if($oop == 'list'){
						$contion = "weid = :weid";
						$params = array(':weid'=>$_W['uniacid']);

						$subjectlist = pdo_fetchall("SELECT * FROM ".tablename('goouc_class_subject')." WHERE ".$contion." ORDER BY `order` DESC",$params);
					}elseif($oop == 'add'){
						$subjectid = $_GPC['subjectid'];
						$subjectinfo = pdo_fetch('SELECT * FROM '.tablename('goouc_class_subject')." WHERE id = :id AND weid = :weid",array(':id'=>$subjectid,':weid'=>$_W['uniacid']));
						if($_W['isajax']){
							return json_encode($subjectinfo);
						}

						if(checksubmit('submit')){
							$data['name'] = trim($_GPC['name']);
							$data['order'] = intval($_GPC['order']);
							$data['status'] = intval($_GPC['status']);
							$data['weid'] = intval($_W['uniacid']);
							if(empty($data['name'])){
								message('学科名称不能为空','','error');
							}

							if(empty($subjectid)){
								$res = pdo_insert('goouc_class_subject',$data);
								if($res){

									$arr = array(
										'weid'=>$_W['uniacid'],
										'admin_uid'=>$_W['uid'],
										'admin_username'=>$_W['username'],
										'log_type'=>1,
										'function'=>'基本设置->学科设置',
										'content'=>'新增学科'
									);
									$this->addlog($arr);
								}
							}else{
								$res = pdo_update('goouc_class_subject',$data,array('weid'=>$_W['uniacid'],'id'=>$subjectid));
								if($res){

									$arr = array(
										'weid'=>$_W['uniacid'],
										'admin_uid'=>$_W['uid'],
										'admin_username'=>$_W['username'],
										'log_type'=>3,
										'function'=>'基本设置->学科设置',
										'content'=>'更改学科信息'
									);
									$this->addlog($arr);
								}
							}
							if($res){
								message('操作成功',$this->createWebUrl('index',array('op'=>'setting','type'=>"subject",'oop'=>'list')),'success');
							}else{
								message('操作失败',$this->createWebUrl('index',array('op'=>'setting','type'=>"subject",'oop'=>'list')),'error');
							}
						}
					}elseif($oop == 'delete'){

						$id = intval($_GPC['subjectid']);
                        $num = pdo_fetch("SELECT * FROM ".tablename('goouc_class_teacher')." WHERE subjectid = :subjectid AND weid = :weid",array(':subjectid'=>$id,':weid'=>$_W['uniacid']));
                        $snum = pdo_fetch("SELECT * FROM ".tablename('goouc_class_lesson')." WHERE subjectid = :subjectid AND weid = :weid",array(':subjectid'=>$id,':weid'=>$_W['uniacid']));
                        if($num || $snum){
                            itoast('该学科下还有老师或课程，不能删除');
                        }
						$res = pdo_delete('goouc_class_subject',array('weid'=>$_W['uniacid'],'id'=>$id));
						if($res){
							$arr = array(
								'weid'=>$_W['uniacid'],
								'admin_uid'=>$_W['uid'],
								'admin_username'=>$_W['username'],
								'log_type'=>2,
								'function'=>'基本设置->学科设置',
								'content'=>'删除学科'
							);
							$this->addlog($arr);
							message('删除成功',$this->createWebUrl('index',array('op'=>'setting','type'=>'subject')),'success');
						}else{
							message('删除失败','','error');
						}
					}elseif($oop == 'changestatus'){
						$id = $_GPC['id'];
						$data['status'] = $_GPC['sta'];
						$info = pdo_get('goouc_class_subject',array('id'=>$id,'weid'=>$_W['uniacid']));
						if($data['status'] == $info['status']){
							$message = array('success'=>0,'修改失败，请刷新页面后重新修改');
						}else{
							$res = pdo_update('goouc_class_subject',$data,array('id'=>$id,'weid'=>$_W['uniacid']));
							if($res){
								$message = array('success'=>1,'mess'=>'修改成功');
							}else{
								$message = array('success'=>0,'mess'=>'修改失败');
							}
						}
						echo json_encode($message);exit;
					}
				}elseif($type == 'semester'){
					if($oop == 'list'){
						$contion = "weid = :weid";
						$params = array(':weid'=>$_W['uniacid']);

						$semesterlist = pdo_fetchall("SELECT * FROM ".tablename('goouc_class_semester')." WHERE ".$contion,$params);
					}elseif($oop == 'add'){
						$semesterid = $_GPC['semesterid'];
						$semesterinfo = pdo_fetch('SELECT * FROM '.tablename('goouc_class_semester')." WHERE id = :id AND weid = :weid",array(':id'=>$semesterid,':weid'=>$_W['uniacid']));
						if($_W['isajax']){
							return json_encode($semesterinfo);
						}

						if(checksubmit('submit')){
							$data['name'] = trim($_GPC['name']);
							$data['status'] = intval($_GPC['status']);
							$data['weid'] = intval($_W['uniacid']);
							$data['addtime'] = time();
							if(empty($data['name'])){
								message('学期名称不能为空','','error');
							}

							if(empty($semesterid)){
								$res = pdo_insert('goouc_class_semester',$data);
								if($res){

									$arr = array(
										'weid'=>$_W['uniacid'],
										'admin_uid'=>$_W['uid'],
										'admin_username'=>$_W['username'],
										'log_type'=>1,
										'function'=>'基本设置->班期设置',
										'content'=>'新增班期'
									);
									$this->addlog($arr);
								}
							}else{
								$res = pdo_update('goouc_class_semester',$data,array('weid'=>$_W['uniacid'],'id'=>$semesterid));
								if($res){

									$arr = array(
										'weid'=>$_W['uniacid'],
										'admin_uid'=>$_W['uid'],
										'admin_username'=>$_W['username'],
										'log_type'=>3,
										'function'=>'基本设置->班期设置',
										'content'=>'更改班期信息'
									);
									$this->addlog($arr);
								}
							}
							if($res){
								message('操作成功',$this->createWebUrl('index',array('op'=>'setting','type'=>"semester",'oop'=>'list')),'success');
							}else{
								message('操作失败',$this->createWebUrl('index',array('op'=>'setting','type'=>"semester",'oop'=>'list')),'error');
							}
						}
					}elseif($oop == 'delete'){

						$id = intval($_GPC['semesterid']);
                        $snum = pdo_fetch("SELECT * FROM ".tablename('goouc_class_lesson')." WHERE semesterid = :semesterid AND weid = :weid",array(':semesterid'=>$id,':weid'=>$_W['uniacid']));
                        if($snum){
                            itoast('该班期下还有课程，不能删除');
                        }
						$res = pdo_delete('goouc_class_semester',array('weid'=>$_W['uniacid'],'id'=>$id));
						if($res){
							$arr = array(
								'weid'=>$_W['uniacid'],
								'admin_uid'=>$_W['uid'],
								'admin_username'=>$_W['username'],
								'log_type'=>2,
								'function'=>'基本设置->班期设置',
								'content'=>'删除班期信息'
							);
							$this->addlog($arr);
							message('删除成功',$this->createWebUrl('index',array('op'=>'setting','type'=>'semester')),'success');
						}else{
							message('删除失败','','error');
						}
					}elseif($oop == 'changestatus'){
						$id = $_GPC['id'];
						$data['status'] = $_GPC['sta'];
						$info = pdo_get('goouc_class_semester',array('id'=>$id,'weid'=>$_W['uniacid']));
						if($data['status'] == $info['status']){
							$message = array('success'=>0,'修改失败，请刷新页面后重新修改');
						}else{
							$res = pdo_update('goouc_class_semester',$data,array('id'=>$id,'weid'=>$_W['uniacid']));
							if($res){
								$message = array('success'=>1,'mess'=>'修改成功');
							}else{
								$message = array('success'=>0,'mess'=>'修改失败');
							}
						}
						echo json_encode($message);exit;
					}
				}elseif($type == 'voidtype'){
					if($oop == 'list'){
						$contion = "weid = :weid";
						$params = array(':weid'=>$_W['uniacid']);

						$voidtypelist = pdo_fetchall("SELECT * FROM ".tablename('goouc_class_voidtype')." WHERE ".$contion,$params);
					}elseif($oop == 'add'){
						$voidtypeid = $_GPC['voidtypeid'];
						$voidtypeinfo = pdo_fetch('SELECT * FROM '.tablename('goouc_class_voidtype')." WHERE id = :id AND weid = :weid",array(':id'=>$voidtypeid,':weid'=>$_W['uniacid']));
						if($_W['isajax']){
							return json_encode($voidtypeinfo);
						}

						if(checksubmit('submit')){
							$data['name'] = trim($_GPC['name']);
							$data['status'] = intval($_GPC['status']);
							$data['weid'] = intval($_W['uniacid']);
							$data['addtime'] = time();
							if(empty($data['name'])){
								message('类型名称不能为空','','error');
							}

							if(empty($voidtypeid)){
								$res = pdo_insert('goouc_class_voidtype',$data);
								if($res){

									$arr = array(
										'weid'=>$_W['uniacid'],
										'admin_uid'=>$_W['uid'],
										'admin_username'=>$_W['username'],
										'log_type'=>1,
										'function'=>'基本设置->视频类型设置',
										'content'=>'新增视频类型'
									);
									$this->addlog($arr);
								}
							}else{
								$res = pdo_update('goouc_class_voidtype',$data,array('weid'=>$_W['uniacid'],'id'=>$voidtypeid));
								if($res){

									$arr = array(
										'weid'=>$_W['uniacid'],
										'admin_uid'=>$_W['uid'],
										'admin_username'=>$_W['username'],
										'log_type'=>3,
										'function'=>'基本设置->视频类型设置',
										'content'=>'更改视频类型信息'
									);
									$this->addlog($arr);
								}
							}
							if($res){
								message('操作成功',$this->createWebUrl('index',array('op'=>'setting','type'=>"voidtype",'oop'=>'list')),'success');
							}else{
								message('操作失败',$this->createWebUrl('index',array('op'=>'setting','type'=>"voidtype",'oop'=>'list')),'error');
							}
						}
					}elseif($oop == 'delete'){

						$id = intval($_GPC['voidtypeid']);
                        $snum = pdo_fetch("SELECT * FROM ".tablename('goouc_class_lesson')." WHERE voidtypeid = :voidtypeid AND weid = :weid",array(':voidtypeid'=>$id,':weid'=>$_W['uniacid']));
                        if($snum){
                            itoast('该视频类型下还有课程，不能删除');
                        }
						$res = pdo_delete('goouc_class_voidtype',array('weid'=>$_W['uniacid'],'id'=>$id));
						if($res){
							$arr = array(
								'weid'=>$_W['uniacid'],
								'admin_uid'=>$_W['uid'],
								'admin_username'=>$_W['username'],
								'log_type'=>2,
								'function'=>'基本设置->视频类型设置',
								'content'=>'删除视频类型信息'
							);
							$this->addlog($arr);
							message('删除成功',$this->createWebUrl('index',array('op'=>'setting','type'=>'voidtype')),'success');
						}else{
							message('删除失败','','error');
						}
					}elseif($oop == 'changestatus'){
						$id = $_GPC['id'];
						$data['status'] = $_GPC['sta'];
						$info = pdo_get('goouc_class_voidtype',array('id'=>$id,'weid'=>$_W['uniacid']));
						if($data['status'] == $info['status']){
							$message = array('success'=>0,'修改失败，请刷新页面后重新修改');
						}else{
							$res = pdo_update('goouc_class_voidtype',$data,array('id'=>$id,'weid'=>$_W['uniacid']));
							if($res){
								$message = array('success'=>1,'mess'=>'修改成功');
							}else{
								$message = array('success'=>0,'mess'=>'修改失败');
							}
						}
						echo json_encode($message);exit;
					}
				}elseif($type == 'level'){
					if($oop == 'list'){
						$contion = "weid = :weid";
						$params = array(':weid'=>$_W['uniacid']);

						$levellist = pdo_fetchall("SELECT * FROM ".tablename('goouc_class_level')." WHERE ".$contion,$params);
					}elseif($oop == 'add'){
						$lvid = $_GPC['lvid'];
						$lvinfo = pdo_fetch('SELECT * FROM '.tablename('goouc_class_level')." WHERE id = :id AND weid = :weid",array(':id'=>$lvid,':weid'=>$_W['uniacid']));
						if($_W['isajax']){
							return json_encode($lvinfo);
						}
						if(checksubmit('submit')){
							$data['name'] = trim($_GPC['name']);
							$data['time'] = intval($_GPC['time']);
							$data['status'] = intval($_GPC['status']);
							$data['weid'] = $_W['uniacid'];
							$data['addtime'] = time();
							if(empty($data['name']) || empty($_GPC['time'])){
								itoast('等级名称/观看时长不能为空','','error');
							}
							if(empty($lvid)){
								$res = pdo_insert('goouc_class_level',$data);
								if($res){
									$arr = array(
										'weid'=>$_W['uniacid'],
										'admin_uid'=>$_W['uid'],
										'admin_username'=>$_W['username'],
										'log_type'=>1,
										'function'=>'基本设置->等级设置',
										'content'=>'新增等级'
									);
									$this->addlog($arr);
								}
							}else{
								$res = pdo_update('goouc_class_level',$data,array('weid'=>$_W['uniacid'],'id'=>$lvid));
								if($res){
									$arr = array(
										'weid'=>$_W['uniacid'],
										'admin_uid'=>$_W['uid'],
										'admin_username'=>$_W['username'],
										'log_type'=>3,
										'function'=>'基本设置->等级设置',
										'content'=>'更改等级信息'
									);
									$this->addlog($arr);
								}
							}
							if($res){
								message('操作成功',$this->createWebUrl('index',array('op'=>'setting','type'=>"level",'oop'=>'list')),'success');
							}else{
								message('操作失败',$this->createWebUrl('index',array('op'=>'setting','type'=>"level",'oop'=>'list')),'error');
							}
						}
					}elseif($oop == 'delete'){
						$id = intval($_GPC['levelid']);
						$res = pdo_delete('goouc_class_level',array('weid'=>$_W['uniacid'],'id'=>$id));
						if($res){
							$arr = array(
								'weid'=>$_W['uniacid'],
								'admin_uid'=>$_W['uid'],
								'admin_username'=>$_W['username'],
								'log_type'=>2,
								'function'=>'基本设置->等级设置',
								'content'=>'删除等级信息'
							);
							$this->addlog($arr);
							message('删除成功',$this->createWebUrl('index',array('op'=>'setting','type'=>'level')),'success');
						}else{
							message('删除失败','','error');
						}
					}elseif($oop == 'changestatus'){
						$id = $_GPC['id'];
						$data['status'] = $_GPC['sta'];
						$info = pdo_get('goouc_class_level',array('id'=>$id,'weid'=>$_W['uniacid']));
						if($data['status'] == $info['status']){
							$message = array('success'=>0,'修改失败，请刷新页面后重新修改');
						}else{
							$res = pdo_update('goouc_class_level',$data,array('id'=>$id,'weid'=>$_W['uniacid']));
							if($res){
								$message = array('success'=>1,'mess'=>'修改成功');
							}else{
								$message = array('success'=>0,'mess'=>'修改失败');
							}
						}
						echo json_encode($message);exit;
					}
				}elseif($type == 'sharetitle'){
					$info = pdo_get('goouc_class_shartitle',array('weid'=>$_W['uniacid']));
					if(checksubmit('submit')){
						$data['selected'] = $_GPC['selected'];
						$data['mine'] = $_GPC['mine'];
						$data['ranking'] = $_GPC['ranking'];
						$data['ranking_detail'] = $_GPC['ranking_detail'];
						$data['myday'] = $_GPC['myday'];
						$data['rechange'] = $_GPC['rechange'];
						$data['consultation'] = $_GPC['consultation'];
						$data['weid'] = $_W['uniacid'];
						if(empty($info)){
							$res = pdo_insert('goouc_class_shartitle',$data);
						}else{
							$res = pdo_update('goouc_class_shartitle',$data,array('id'=>$info['id']));
						}
						if($res){
							message('保存成功',$this->createWebUrl('index',array('op'=>'setting','type'=>'sharetitle')),'success');
						}else{
							message('保存失敗',$this->createWebUrl('index',array('op'=>'setting','type'=>'sharetitle')),'error');
						}
					}
				}
			}
			include $this->template('web/setting');
		}

		public function doWebModule(){
			global $_W,$_GPC;
			load()->func('tpl');
			$op = empty($_GPC['op'])?'list':$_GPC['op'];
			if($op == 'list'){
				$params = array('weid'=>$_W['uniacid']);
				$modulelist = pdo_fetchall("SELECT * FROM ".tablename('goouc_class_module')." WHERE weid = :weid  ORDER BY `order` DESC",$params);
			}elseif($op == 'post'){
				$id = intval($_GPC['id']);
				$info = pdo_fetch("SELECT * FROM ".tablename('goouc_class_module')." WHERE id = :id AND weid = :weid",array(':weid'=>$_W['uniacid'],':id'=>$id));
				if(checksubmit('submit')){
					if(empty($_GPC['name'])){
						message('模块名不能为空','','error');
					}
					$data['weid'] = $_W['uniacid'];
					$data['name'] = trim($_GPC['name']);
					$data['order'] = intval($_GPC['order']);
					$data['num'] = intval($_GPC['num']);
					$data['status'] = intval($_GPC['status']);
					$data['image'] = trim($_GPC['image']);
					$data['addtime'] = time();
					if(empty($id)){
						$res = pdo_insert('goouc_class_module',$data);
						if($res){
							$arr = array(
								'weid'=>$_W['uniacid'],
								'admin_uid'=>$_W['uid'],
								'admin_username'=>$_W['username'],
								'log_type'=>1,
								'function'=>'推荐模块->模块设置',
								'content'=>'新增推荐模块'
							);
							$this->addlog($arr);
							message('新增模块成功',$this->createWebUrl('module'),'succss');
						}else{
							message('操作失败','','error');
						}
					}else{
						$res = pdo_update('goouc_class_module',$data,array('id'=>$id,'weid'=>$_W['uniacid']));
						if($res){
							$arr = array(
								'weid'=>$_W['uniacid'],
								'admin_uid'=>$_W['uid'],
								'admin_username'=>$_W['username'],
								'log_type'=>3,
								'function'=>'推荐模块->模块设置',
								'content'=>'修改模块信息'
							);
							$this->addlog($arr);
							message('修改模块成功',$this->createWebUrl('module'),'succss');
						}else{
							message('操作失败','','error');
						}
					}
				}
			}elseif($op == 'delete'){
				$mid = intval($_GPC['id']);
                $has = pdo_getall('goouc_class_lesson',array('moduleid'=>$mid,'weid'=>$_W['uniacid']));
                if($has){
                    itoast('请先将模块下的课程移除！！！');
                }
                $res = pdo_delete('goouc_class_module',array('id'=>$mid,'weid'=>$_W['uniacid']));
                if($res){
                    $arr = array(
                        'weid'=>$_W['uniacid'],
                        'admin_uid'=>$_W['uid'],
                        'admin_username'=>$_W['username'],
                        'log_type'=>2,
                        'function'=>'推荐模块->模块设置',
                        'content'=>'删除模块信息'
                    );
                    $this->addlog($arr);
                    message('删除模块成功',$this->createWebUrl('module'),'succss');
                }else{
                    message('操作失败','','error');
                }
				message('操作成功',$this->createWebUrl('module'),'success');
			}elseif($op == 'lessonlist'){
				$mid = intval($_GPC['id']);
                $lesson_list = pdo_getall('goouc_class_lesson',array('moduleid'=>$mid,'weid'=>$_W['uniacid']));
                foreach($lesson_list as $k=>$v){
                    $lesson_list[$k]['snum'] = count(pdo_getall('goouc_class_son',array('lessonid'=>$v['id']),array('id')));
                }
			}elseif($op == 'removelesson'){
			    $lid = $_GPC['id'];
			    $mid = $_GPC['mid'];
			    $data['moduleid'] = 0;
			    $res = pdo_update('goouc_class_lesson',$data,array('id'=>$lid,'weid'=>$_W['uniacid']));
			    if($res){
                    message('移除成功',$this->createWebUrl('module',array('op'=>'lessonlist','id'=>$mid)));
                }
            }
			include $this->template('web/module');
		}

		public function doWebSyslog(){
			global $_W,$_GPC;

			$query = load()->object('query');
			$pageindex = max(1,intval($_GPC['page']));
			$contion = "weid = :weid";
			$psize = 10;
			$params = array(':weid'=>$_W['uniacid']);
			$admin_username = trim($_GPC['admin_username']);
			if($admin_username != ''){
				$contion .= " AND admin_username LIKE :admin_username";
				$params[':admin_username'] = "%".$admin_username."%";
			}
			$log_type = intval($_GPC['log_type']);
			if($log_type >= 1){
				$contion .= " AND log_type = :log_type";
				$params[':log_type'] = $log_type;
			}

			if(!empty($_GPC['time'])){
				$starttime = strtotime($_GPC['time']['start']);
				$endtime = strtotime($_GPC['time']['end']) +86399;
				$contion .= " AND addtime >= :starttime AND addtime <= :endtime";
				$params[':starttime'] = $starttime;
				$params[':endtime'] = $endtime;
			}else{
				$starttime = strtotime('-1 month');
				$endtime = time();	
			}
			$sysloglist = pdo_fetchall("SELECT * FROM ".tablename('goouc_class_syslog')." WHERE ".$contion." ORDER BY `addtime` DESC LIMIT ".($pageindex - 1)*$psize.",".$psize,$params);
			$total = pdo_fetchcolumn("SELECT count(*) FROM ".tablename('goouc_class_syslog')." WHERE ".$contion,$params);
			$page = pagination($total,$pageindex,$psize);
			include $this->template('web/syslog');
		}

		public function doWebTeacher(){
			global $_W,$_GPC;
			$op = trim(empty($_GPC['op'])?'list':$_GPC['op']);
			if($op == 'list'){
				$city = pdo_fetchall("SELECT * FROM " .tablename('goouc_class_city')." WHERE weid = :weid",array(':weid'=>$_W['uniacid']));
				$subject = pdo_fetchall("SELECT * FROM " .tablename('goouc_class_subject')." WHERE weid = :weid",array(':weid'=>$_W['uniacid']));
				$psize = 10;
				$pageindex = max(1,$_GPC['page']);
				$contion = " weid = :weid";
				$params[':weid'] = $_W['uniacid'];
				$kname = trim($_GPC['kname']);
				if($kname != ''){
					$contion .= " AND name LIKE :name";
					$params[':name'] = "%".$kname."%";
				}
				$cityid = intval($_GPC['cityid']);
				if($cityid >0){
					$contion .= " AND cityid = :cityid";
					$params[':cityid'] = $cityid;
				}
				$subjectid = intval($_GPC['subjectid']);
				if($subjectid > 0){
					$contion .= " AND subjectid = :subjectid";
					$params[':subjectid'] = $subjectid;
				}
				$teacherlist = pdo_fetchall("SELECT * FROM ".tablename('goouc_class_teacher')." WHERE ".$contion." ORDER BY `order` DESC LIMIT ".($pageindex - 1)*$psize.",".$psize,$params);
				foreach($teacherlist as $k=>$v){
					$teacherlist[$k]['cityname'] = pdo_fetch("SELECT `name` FROM ".tablename('goouc_class_city')." WHERE id = :id",array(':id'=>$v['cityid']));
					$teacherlist[$k]['subjectname'] = pdo_fetch("SELECT `name` FROM ".tablename('goouc_class_subject')." WHERE weid = :weid AND id = :id",array(':weid'=>$_W['uniacid'],':id'=>$v['subjectid']));
				}
				$tatol = pdo_fetchcolumn("SELECT COUNT(*) FROM ".tablename('goouc_class_teacher')." WHERE ".$contion,$params);
				$page = pagination($tatol,$pageindex,$psize);
			}elseif($op == 'post'){
				$id = intval($_GPC['id']);
				$info = pdo_fetch('SELECT * FROM '.tablename("goouc_class_teacher")." WHERE id = :id AND weid = :weid",array(':id'=>$id,':weid'=>$_W['uniacid']));

				$city = pdo_fetchall("SELECT * FROM ".tablename('goouc_class_city')." WHERE weid = :weid",array(':weid'=>$_W['uniacid']));
				$subject = pdo_fetchall("SELECT * FROM ".tablename('goouc_class_subject')." WHERE weid = :weid",array(':weid'=>$_W['uniacid']));

				if(checksubmit('submit')){
					$data['weid'] = $_W['uniacid'];
					$data['name'] = trim($_GPC['name']);
					$data['cityid'] = intval($_GPC['cityid']);
					$data['subjectid'] = intval($_GPC['subjectid']);
					$data['order'] = intval($_GPC['order']);
					$data['status'] = intval($_GPC['status']);
					$data['addtime'] = time();
					if(empty($data['name']) || empty($data['cityid']) || empty($data['subjectid'])){
						itoast('讲师姓名，城市和学科不能為空','','error');
					}
					if(empty($id)){
						$res = pdo_insert('goouc_class_teacher',$data);
						if($res){
							$arr = array(
								'weid'=>$_W['uniacid'],
								'admin_uid'=>$_W['uid'],
								'admin_username'=>$_W['username'],
								'log_type'=>1,
								'function'=>'讲师管理->新增讲师',
								'content'=>'新增讲师'
							);
							$this->addlog($arr);
							message('操作成功',$this->createWebUrl('teacher'),'succss');
						}
					}else{
						$res = pdo_update('goouc_class_teacher',$data,array('id'=>$id));
						if($res){
							$arr = array(
								'weid'=>$_W['uniacid'],
								'admin_uid'=>$_W['uid'],
								'admin_username'=>$_W['username'],
								'log_type'=>3,
								'function'=>'讲师管理->新增讲师',
								'content'=>'更新讲师信息'
							);
							$this->addlog($arr);
							message('操作成功',$this->createWebUrl('teacher'),'succss');
						}
					}
				}
			}elseif($op == 'delete'){
				$id = intval($_GPC['id']);
				$has = pdo_getall('goouc_class_lesson',array('teacherid'=>$id,'weid'=>$_W['uniacid']));
				if(!empty($has)){
					itoast('讲师存在课程学习，不能删除讲师','error');
				}
				$res = pdo_delete('goouc_class_teacher',array('weid'=>$_W['uniacid'],'id'=>$id));
				
				if($res){
					if($res){
						$arr = array(
							'weid'=>$_W['uniacid'],
							'admin_uid'=>$_W['uid'],
							'admin_username'=>$_W['username'],
							'log_type'=>2,
							'function'=>'讲师管理->删除讲师',
							'content'=>'删除讲师'
						);
						$this->addlog($arr);
						message('操作成功',$this->createWebUrl('teacher'),'succss');
					}
				}
			}
			include $this->template('web/teacher');
		}

		public function doWebLesson(){
			global $_W,$_GPC;
			$config = $this->module['config'];
			$op = trim(empty($_GPC['op'])?'list':$_GPC['op']);
			$city = pdo_getall("goouc_class_city",array('status'=>1,'weid'=>$_W['uniacid']));
			$teacher = pdo_getall("goouc_class_teacher",array('status'=>1,'weid'=>$_W['uniacid']));
			$subject = pdo_getall("goouc_class_subject",array('status'=>1,'weid'=>$_W['uniacid']));
			$class = pdo_getall("goouc_class_class",array('status'=>1,'weid'=>$_W['uniacid']));
			$semester = pdo_getall("goouc_class_semester",array('status'=>1,'weid'=>$_W['uniacid']));
			$voidtype = pdo_getall("goouc_class_voidtype",array('status'=>1,'weid'=>$_W['uniacid']));

			$year = pdo_fetchall("SELECT `yearid` FROM ".tablename('goouc_class_lesson')." WHERE weid = :weid GROUP BY yearid",array(':weid'=>$_W['uniacid']));
			$aliyunVod = new AliyunVod($config['regionId'],$config['AccessKeyID'],$config['AccessKeySecret']);
			if($op == 'list'){
				$contion = "l.weid = :weid";
				$params[':weid'] = $_W['uniacid'];
				$kname = trim($_GPC['kname']);
				if($kname != ""){
					$contion .= " AND l.title LIKE :kname";
					$params[':kname'] = "%".$kname."%";
				}
				$cityid = intval($_GPC['cityid']);
				if($cityid > 0){
					$contion .= " AND l.cityid = :cityid";
					$params[':cityid'] = $cityid;
				}
				$subjectid = intval($_GPC['subjectid']);
				if($subjectid > 0){
					$contion .= " AND l.subjectid = :subjectid";
					$params[':subjectid'] = $subjectid;
				}
				$teacherid = intval($_GPC['teacherid']);
				if($teacherid > 0){
					$contion .= " AND l.teacherid = :teacherid";
					$params[':teacherid'] = $teacherid;
				}
				$classid = intval($_GPC['classid']);
				if($classid > 0){
					$contion .= " AND classid LIKE '%\"".$classid."\"%'";
				}
				$semesterid = intval($_GPC['semesterid']);
				if($semesterid > 0){
					$contion .= " AND l.semesterid = :semesterid";
					$params[':semesterid'] = $semesterid;
				}
				$voidtypeid = intval($_GPC['voidtypeid']);
				if($voidtypeid > 0){
					$contion .= " AND l.voidtypeid = :voidtypeid";
					$params[':voidtypeid'] = $voidtypeid;
				}
				$yearid = intval($_GPC['yearid']);
				if($yearid > 0){
					$contion .= " AND l.yearid = :yearid";
					$params[':yearid'] = $yearid;
				}

				$psize = 10;
				$pageindex = max(1,$_GPC['page']);

				$lessonlist = pdo_fetchall("SELECT l.id,l.title,l.image,l.order,l.status,l.classid,l.recommend,t.name as tname,s.name as sname,c.name as cname,v.name as vname,l.pay_money,l.pay_num,l.moduleid,l.qrcode FROM ".tablename('goouc_class_lesson')."as l JOIN ".tablename('goouc_class_teacher')." as t ON l.teacherid = t.id JOIN ".tablename('goouc_class_city')." as c ON l.cityid = c.id JOIN ".tablename('goouc_class_subject')." as s ON l.subjectid = s.id JOIN ".tablename('goouc_class_semester')." as se ON l.semesterid = se.id JOIN ".tablename('goouc_class_voidtype')." as v ON l.voidtypeid = v.id  WHERE ".$contion." ORDER BY `order` DESC,`id` DESC LIMIT ".($pageindex - 1)*$psize.",".$psize,$params);
				$errornum = 0;
				foreach($lessonlist as $k=>$v){
				    if($v['moduleid'] > 0){
                        $lessonlist[$k]['mname'] = pdo_get('goouc_class_module',array('id'=>$v['moduleid'],'weid'=>$_W['uniacid']))['name'];
                    }
                    $lessonlist[$k]['count'] = pdo_fetchcolumn("SELECT COUNT(*) FROM ".tablename('goouc_class_son')." WHERE weid=:weid AND lessonid=:lessonid AND updatestatus=0",array(':weid'=>$_W['uniacid'],':lessonid'=>$v['id']));
                    //查询一下下面的整洁视频是否有问题
                    $lessonlist[$k]['son'] = pdo_getall('goouc_class_son',array('lessonid'=>$v['id'],'weid'=>$_W['uniacid']));
                    foreach($lessonlist[$k]['son'] as $kk=>$vv){
                    	try {
                    		$video = $aliyunVod->getPlayInfo($vv['key']);
                    	} catch (Exception $e) {
                    		pdo_update('goouc_class_son',array('status'=>0),array('id'=>$vv['id']));
                    		$errornum ++;
                    		// 给lessonlist一个字段  提示有不合法的视频
                    		$lessonlist[$k]['errornum'] = $errornum;
                    	}
                    }
                }
				$tatol = pdo_fetchcolumn("SELECT COUNT(*) FROM".tablename('goouc_class_lesson')." as l WHERE ".$contion,$params);
				$page = pagination($tatol,$pageindex,$psize);
			}elseif($op == 'post'){
				$id = intval($_GPC['id']);
				$info = pdo_fetch("SELECT l.id,l.title,l.share_image,l.image,l.order,l.status,l.old_money,l.fic_study_num,l.fic_pay_num,l.pc_description,l.classid,t.name as tname,l.desc,t.id as tid,s.name as sname,s.id as sid,c.name as cname,c.id as cid,se.id as seid,v.name as vname,v.id as vid,l.pay_money,l.pay_num,l.yearid FROM ".tablename('goouc_class_lesson')."l JOIN ".tablename('goouc_class_teacher')." as t ON l.teacherid = t.id JOIN ".tablename('goouc_class_city')." as c ON l.cityid = c.id JOIN ".tablename('goouc_class_subject')." as s ON l.subjectid = s.id JOIN ".tablename('goouc_class_semester')." as se ON l.semesterid = se.id JOIN ".tablename('goouc_class_voidtype')." as v ON l.voidtypeid = v.id  WHERE l.weid = :weid AND l.id = :id",array(":weid"=>$_W['uniacid'],':id'=>$id));
				$info['classid'] = unserialize($info['classid']);
				$class = pdo_fetchall("SELECT * FROM ".tablename('goouc_class_class')." WHERE subjectid LIKE '%\"".$info['sid']."\"%'");

				$teacherlist = pdo_fetchall("SELECT `id`,`name` FROM ".tablename('goouc_class_teacher')." WHERE weid = :weid",array(':weid'=>$_W['uniacid']));
				$voidtype = pdo_fetchall("SELECT `id`,`name` FROM ".tablename('goouc_class_voidtype')." WHERE weid = :weid",array(':weid'=>$_W['uniacid']));

				$semester = pdo_fetchall("SELECT `id`,`name` FROM ".tablename('goouc_class_semester')." WHERE weid = :weid",array(':weid'=>$_W['uniacid']));
				if($_W['isajax']){
					$teacherid = intval($_GPC['teacherid']);
					$tinfo = pdo_fetch("SELECT * FROM ".tablename('goouc_class_teacher')."WHERE id = :id AND weid = :weid",array(':id'=>$teacherid,':weid'=>$_W['uniacid']));

					$city = pdo_fetch("SELECT `id`,`name` FROM ".tablename('goouc_class_city')." WHERE id = :id AND weid = :weid",array(':id'=>$tinfo['cityid'],':weid'=>$_W['uniacid']));
					$subject = pdo_fetch("SELECT `id`,`name` FROM ".tablename('goouc_class_subject')." WHERE id = :id AND weid = :weid",array(':id'=>$tinfo['subjectid'],':weid'=>$_W['uniacid']));

					$class = pdo_fetchall("SELECT * FROM ".tablename('goouc_class_class')." WHERE weid = :weid AND subjectid LIKE '%\"".$subject['id']."\"%'",array(':weid'=>$_W['uniacid']));
					$arr = array('city'=>$city,'subject'=>$subject,'class'=>$class);
					echo json_encode($arr);exit;
				}
				if(checksubmit('submit')){
					$id = intval($_GPC['id']);

					$data = array(
						'weid'=>$_W['uniacid'],
						'title'=>trim($_GPC['title']),
						'image'=>trim($_GPC['image']),//PC端封面图片
						'teacherid'=>intval($_GPC['teacherid']),
						'subjectid'=>intval($_GPC['subjectid']),
						'cityid'=>intval($_GPC['cityid']),
						'classid'=>serialize($_GPC['classid']),
						'voidtypeid'=>intval($_GPC['voidtypeid']),
						'semesterid'=>intval($_GPC['semesterid']),
						'yearid'=>intval($_GPC['yearid']),
						'status'=>intval($_GPC['status']),
						'addtime'=>time(),
                        'old_money'=>empty($_GPC['old_money'])?'0.00':round($_GPC['old_money'],2),
                        'fic_study_num'=>$_GPC['fic_study_num'],
                        'fic_pay_num'=>$_GPC['fic_pay_num'],
                        'pc_description'=>$_GPC['pc_description'],
                        'free_num'=>$_GPC['free_num'],
                        'order'=>$_GPC['order'],
                        'desc'=>$_GPC['desc'],
                        'recommend'=>$_GPC['recommend'],
                        'share_image'=>$_GPC['share_image'],
					);
					if(empty($data['teacherid']) || empty($data['subjectid']) || empty($data['cityid']) || empty($data['voidtypeid']) || empty($data['semesterid']) || empty($data['share_image'])){
						itoast('讲师、学科、城市、视频类型、班期、分享封面图片选择不能为空');
					}
					$data['pay_money'] = empty($_GPC['pay_money'])?'0.00':round($_GPC['pay_money'],2);
					if(empty($id)){
						$res = pdo_insert('goouc_class_lesson',$data);
						if($res){
							$arr = array(
								'weid'=>$_W['uniacid'],
								'admin_uid'=>$_W['uid'],
								'admin_username'=>$_W['username'],
								'log_type'=>1,
								'function'=>'课程管理->新增课程',
								'content'=>'新增课程'
							);
							$this->addlog($arr);
							message('操作成功',$this->createWebUrl('lesson'),'succss');
						}else{
							message('操作失败',$this->createWebUrl('lesson'),'error');
						}
					}else{
						$res = pdo_update('goouc_class_lesson',$data,array('id'=>$id));
						if($res){
							$arr = array(
								'weid'=>$_W['uniacid'],
								'admin_uid'=>$_W['uid'],
								'admin_username'=>$_W['username'],
								'log_type'=>3,
								'function'=>'课程管理->修改课程',
								'content'=>'修改课程'
							);
							$this->addlog($arr);
							message('操作成功',$this->createWebUrl('lesson'),'succss');
						}else{
							message('操作失败',$this->createWebUrl('lesson'),'error');
						}
					}
				}
			}elseif($op == 'delete'){
				$id = intval($_GPC['id']);
				$sonlist = pdo_fetch("SELECT * FROM ".tablename('goouc_class_son').' WHERE lessonid = :lessonid AND weid = :weid',array(':lessonid'=>$id,":weid"=>$_W['uniacid']));

				if($sonlist > 0){
					itoast('课程下有章节信息，不能删除课程','error');
				}
				$res = pdo_delete('goouc_class_lesson',array('id'=>$id));
				if($res){
					$arr = array(
						'weid'=>$_W['uniacid'],
						'admin_uid'=>$_W['uid'],
						'admin_username'=>$_W['username'],
						'log_type'=>2,
						'function'=>'课程管理->删除课程',
						'content'=>'删除课程'
					);
					$this->addlog($arr);
					message('操作成功',$this->createWebUrl('lesson'),'succss');
				}else{
					message('操作失败',$this->createWebUrl('lesson'),'error');
				}
			}elseif($op == 'cstatus'){
				$id = $_GPC['id'];
				$sta = $_GPC['sta'];
				$data['status'] = $sta;

				$info = pdo_get('goouc_class_lesson',array('id'=>$id,'weid'=>$_W['uniacid']));
				if($sta == $info['status']){
					$message = array('success'=>3,'mess'=>'更改失败，请刷新页面后再更改');
				}else{
					$res = pdo_update('goouc_class_lesson',$data,array('id'=>$id,'weid'=>$_W['uniacid']));
					if($res){
						$message = array('success'=>1,'mess'=>'更改成功');
					}else{
						$message = array('success'=>0,'mess'=>'更改失败');						
					}
				}
				echo json_encode($message);exit;
			}elseif($op == 'module'){
               //获取一下模块的列表
                if($_W['isajax']){
                    $lid = $_GPC['lid'];
                    $m_list = pdo_getall('goouc_class_module',array('weid'=>$_W['uniacid'],'status'=>1),array('id','name'));
                    return include $this->template('web/choose');die;
                }
            }elseif($op == 'selectm'){
			    //一个课程对应一个模块
                if($_W['isajax']){
                    $mid = $_GPC['mid'];
                    $lid = $_GPC['lid'];
                    $data['moduleid'] = $mid;
                   //查询一下当前课程对应的模块值为0  则添加 否则不添加
                    $res = pdo_update('goouc_class_lesson',$data,array('id'=>$lid,'weid'=>$_W['uniacid']));
                    if($res){
                        $message = array('success'=>1,'mess'=>'添加成功');
                    }else{
                        $message = array('success'=>0,'mess'=>'添加失败');
                    }
                    echo json_encode($message);exit;
                }
            }elseif($op == 'recommend'){
            	if($_W['isajax']){
            		$id = $_GPC['id'];
            		$sta = $_GPC['sta'];
            		$data['recommend'] = $sta;
            		$info = pdo_get('goouc_class_lesson',array('id'=>$id,'weid'=>$_W['uniacid']));
            		if($sta == $info['recommend']){
						$message = array('success'=>3,'mess'=>'更改失败，请刷新页面后再更改');
					}else{
						$res = pdo_update('goouc_class_lesson',$data,array('id'=>$id,'weid'=>$_W['uniacid']));
						if($res){
							$message = array('success'=>1,'mess'=>'更改成功');
						}else{
							$message = array('success'=>0,'mess'=>'更改失败');						
						}
					}
					echo json_encode($message);exit;
            	}
            }elseif($op == 'qrcode'){
            	if($_W['isajax']){
	            	$lessonid = $_GPC['lessonid'];
            		//静态
	            	$appid = $_W['account']['key'];
			        $secret= $_W['account']['secret'];
			    	$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret;
			    	$access_token =json_decode($this->curl_get($url),true)['access_token'];
			    	$data = array();
			        $data['page'] = 'pages/selected/selected';//路径
			        $data['scene'] = 'p=SD&l='.$lessonid;
			        // $data['width'] = 430;
			        $data = json_encode($data);
			        $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=".$access_token;
			        $da = $this->get_http_array($url,$data);
			        // 生成一个图片
			        $path = MODULE_ROOT.'/Qrcode/lesson/';
					if(!is_dir($path)){
			        	mkdir($path);
					}
			        $filename = $lessonid.'_课程.jpg';
			        file_put_contents($path.$filename, $da);

			        $res = pdo_update('goouc_class_lesson',array('qrcode'=>MODULE_URL.'Qrcode/lesson/'.$filename),array('weid'=>$_W['uniacid'],'id'=>$lessonid));
	        		$qrcode = MODULE_URL.'Qrcode/lesson/'.$filename;
	        		if($res){
	        			$message = array('success'=>1,'mess'=>$qrcode);
	        		}else{
	        			$message = array('success'=>0);
	        		}
	        		echo json_encode($message);exit;

            	}
            }elseif($op == 'download'){
            	$lessonid = $_GPC['lessonid'];
            	$lessoninfo = pdo_get('goouc_class_lesson',array('id'=>$lessonid,'weid'=>$_W['uniacid']));
            	$path = MODULE_ROOT.'/Qrcode/lesson/';
            	$filename = $lessonid.'_课程.jpg';
            	header('Content-Type:text/html;charset=utf-8');
				header("Content-Type: application/jpg");
				header("Content-Transfer-Encoding: Binary");
				header("Content-Length: ".filesize($path.$filename));
				header("Content-Disposition: attachment; filename=\"$filename\"");
				readfile($path.$filename);
            }
			include $this->template('web/lesson');
		}

		public function doWebSon(){
			global $_W,$_GPC;
			include_once MODULE_ROOT."/inc/common/AliyunVod.php";
            $config = $this->module['config'];
            $aliyunVod = new AliyunVod($config['regionId'],$config['AccessKeyID'],$config['AccessKeySecret']);
			$lid = intval($_GPC['lid']);
			$op = trim(empty($_GPC['op'])?'list':$_GPC['op']);
			$lessonname = pdo_get("goouc_class_lesson",array('id'=>$lid,'weid'=>$_W['uniacid']));
			if($op == 'list'){
				$sonlist = pdo_fetchall("SELECT * FROM".tablename("goouc_class_son")." WHERE lessonid = :lessonid AND weid = :weid",array(':lessonid'=>$lessonname['id'],':weid'=>$_W['uniacid']));
				$ac = trim(empty($_GPC['ac']))?'':$_GPC['ac'];
				foreach ($sonlist as $key => $value) {
					try{
                        $aliyunVod->getPlayInfo($value['key']);
                    }catch(Exception $e){
                        pdo_update('goouc_class_son',array('status'=>0),array('id'=>$value['id']));
                        $sonlist[$key]['vstatus'] = 404;
                    }
				}
				if($_W['isajax']){
					$id = intval($_GPC['id']);
					$info = pdo_fetch("SELECT * FROM ".tablename('goouc_class_son')." WHERE id = :id",array(':id'=>$id));
					if(empty($info)){
						message('信息不存在','','error');
					}
					try{
                        $response = $aliyunVod->getVideoPlayAuth($info['key']);
                        $aa = $aliyunVod->getPlayInfo($info['key']);
                    }catch(Exception $e){
                        return json_encode($e->getMessage());exit;
                    }
					$info['response2'] = $aa->VideoBase->CoverURL;
					$info['playAuth'] = $response->PlayAuth;
					$info['aa'] = $aa;
					return json_encode($info);
				}
			}elseif($op == 'getUploadInfo'){
                try{
                    $aliyunVod = new AliyunVod($config['regionId'],$config['AccessKeyID'],$config['AccessKeySecret']);
                    $filename = trim($_GPC['filename']);
                    $suffix = substr(strrchr($filename,'.'),1);
                    $title = str_replace('.'.$suffix,"" , $filename);
                    $response = $aliyunVod->create_upload_video($title,$filename);
                }catch(Exception $e){
                    return json_encode($e->getMessage());exit;
                }
                echo json_encode($response);exit;
			}elseif($op == 'post'){
				$sonid = intval($_GPC['id']);
				$info = pdo_fetch("SELECT * FROM ".tablename('goouc_class_son')." WHERE id = :id AND weid = :weid",array(':id'=>$sonid,':weid'=>$_W['uniacid']));
				if($_W['isajax']){
					$id = intval($_GPC['id']);
					$status = trim($_GPC['status']);
					$type = trim($_GPC['type']);
					if(!empty($status)){
						//判断一下 视频是否有效  无效的话 不让上架
						$soninfo = pdo_get('goouc_class_son',array('weid'=>$_W['uniacid'],'id'=>$id));
						if($soninfo['key'] == ''){
							$data['status'] = 0;
							pdo_update("goouc_class_son",$data,array('id'=>$id,'weid'=>$_W['uniacid']));
							$message = array('success'=>0,'mess'=>'视频无效，章节不能上架');
						}else{
							if($status == '上架'){
								$data['status'] = 0;
							}elseif($status == '下架'){
								$data['status'] = 1;
							}
							$res = pdo_update("goouc_class_son",$data,array('id'=>$id,'weid'=>$_W['uniacid']));
							$message = array('success'=>1,'mess'=>'状态更改成功');
						}
						return json_encode($message);exit;
						
					}else{
						if($type == '需要'){
							$data['type'] = 0;
						}elseif($type == '不需要'){
							$data['type'] = 1;
						}
						$res = pdo_update("goouc_class_son",$data,array('id'=>$id,'weid'=>$_W['uniacid']));
						return json_encode($res);
					}
					
				}
				if(checksubmit('submit')){
					$data['weid'] = $_W["uniacid"];
					$data['title'] = trim($_GPC["title"]);
					$data['type'] = intval($_GPC["type"]);
					$data['lessonid'] = intval($_GPC["lessonid"]);
					$data['key'] = trim($_GPC["videoId"]);
					$data['image'] = trim($_GPC["image"]);
					$data['status'] = intval($_GPC["status"]);
					$data['object'] = 1;
					$data['orders'] = intval($_GPC['order']);
					$data['pay_money'] = empty($_GPC['pay_money'])?'0.00':round($_GPC['pay_money'],2);
                    $data['xnum'] = intval($_GPC['xnum']);
                    $data['cardnum'] = intval($_GPC['cardnum']);
					if(empty($data['title']) || empty($data['image']) || empty($data['key'])){
						itoast('请填写完整信息的信息','','error');
					}
					if(empty($sonid)){
						$data['updatestatus'] = 1;
						$res = pdo_insert("goouc_class_son",$data);
						if($res){
							$arr = array(
								'weid'=>$_W['uniacid'],
								'admin_uid'=>$_W['uid'],
								'admin_username'=>$_W['username'],
								'log_type'=>1,
								'function'=>'课程管理->新增章节',
								'content'=>'新增章节'
							);
							$this->addlog($arr);
							message('操作成功',$this->createWebUrl('son',array('lid'=>$data['lessonid'])),'succss');
						}else{
							message('操作失败',$this->createWebUrl('son',array('lid'=>$data['lessonid'])),'error');
						}
					}else{
						if($info['key'] != $_GPC['videoId']){
							$data['updatestatus'] = 1;
						}
						$res = pdo_update('goouc_class_son',$data,array('id'=>$sonid));
						if($res){
							$arr = array(
								'weid'=>$_W['uniacid'],
								'admin_uid'=>$_W['uid'],
								'admin_username'=>$_W['username'],
								'log_type'=>3,
								'function'=>'课程管理->修改章节',
								'content'=>'修改章节'
							);
							$this->addlog($arr);
							message('操作成功',$this->createWebUrl('son',array('lid'=>$data['lessonid'])),'succss');
						}else{
							message('操作失败',$this->createWebUrl('son',array('lid'=>$data['lessonid'])),'error');
						}
					}
				}
			}elseif($op == 'delete'){
				$id = intval($_GPC['id']);
				$info = pdo_fetch("SELECT * FROM ".tablename('goouc_class_son')." WHERE id = :id",array(':id'=>$id));
				if(empty($info)){
					message('章节信息不存在','','error');
				}
				$res = pdo_delete('goouc_class_son',array('id'=>$id));
                $aliyunVod = new AliyunVod($config['regionId'],$config['AccessKeyID'],$config['AccessKeySecret']);
				if($res){
					$aliyunVod->delete_videos($info['key']);
					$arr = array(
						'weid'=>$_W['uniacid'],
						'admin_uid'=>$_W['uid'],
						'admin_username'=>$_W['username'],
						'log_type'=>2,
						'function'=>'课程管理->删除章节',
						'content'=>'删除章节'
					);
					$this->addlog($arr);
					message('操作成功',$this->createWebUrl('son',array('lid'=>$info['lessonid'])),'succss');
				}else{
					message('操作失败',$this->createWebUrl('son',array('lid'=>$info['lessonid'])),'error');
				}
			}elseif($op == 'order'){
				if($_W['isajax']){
					$id = intval($_GPC['id']);
					$data['orders'] = intval($_GPC['order']);
					$res = pdo_update('goouc_class_son',$data,array('id'=>$id,'weid'=>$_W['uniacid']));
					return json_encode($res);
				}
			}elseif($op == 'changevedio'){
				if($_W['isajax']){
					$aliyunVod = new AliyunVod($config['regionId'],$config['AccessKeyID'],$config['AccessKeySecret']);
					$key = $_GPC['key'];
					$sonid = $_GPC['sonid'];
					try {
						$res = $aliyunVod->delete_videos($key);
					} catch (Exception $e) {
						pdo_update('goouc_class_son',array('key'=>'','status'=>0),array('id'=>$sonid));
						$message = array('success'=>404,'mess'=>$e->getMessage());
						echo json_encode($message);exit;
					}
					if($res){
						try {
							pdo_update('goouc_class_son',array('key'=>'','status'=>0),array('id'=>$sonid));
							echo json_encode(array('success'=>1,'mess'=>'数据库删除key值成功'));exit;
						} catch (Exception $e) {
							echo json_encode(array('success'=>401,'mess'=>'数据库删除key失败'));exit;
						}
					}
				}
			}elseif($op == 'card'){
				if($_W['isajax']){
					$id = intval($_GPC['id']);
					$data['cardnum'] = intval($_GPC['cardnum']);
					$res = pdo_update('goouc_class_son',$data,array('id'=>$id,'weid'=>$_W['uniacid']));
					return json_encode($res);
				}
			}
			include $this->template('web/son');
		}

		public function doWebUser(){
			global $_W,$_GPC;
			$op = trim(empty($_GPC['op'])?'list':$_GPC['op']);
			if($op == 'list'){
				$contion = "weid = :weid ";
				$params[':weid'] = $_W['uniacid'];
				$keyword = $_GPC['keyword'];
				if(!empty($_GPC['keyword'])){
                    $contion .= " AND ( nickname LIKE '%".$keyword."%' OR name LIKE '%".$keyword."%' OR phone LIKE '%".$keyword."%')";
                }
				$pageindex = max(1,$_GPC['page']);
				$psize = 15;
				$userlist = pdo_fetchall("SELECT * FROM ".tablename('goouc_class_user')." WHERE ".$contion.' ORDER BY createtime DESC LIMIT '.($pageindex - 1)*$psize.','.$psize,$params);
				foreach($userlist as $k=>$v){
					$userlist[$k]['looktime'] = pdo_get('goouc_class_userlook',array('uid'=>$v['id']))['time'];
					$userlist[$k]['looktimem'] = pdo_get('goouc_class_userlookm',array('uid'=>$v['id']))['time'];
				}
				$total = pdo_fetchcolumn("SELECT count(*) FROM ".tablename('goouc_class_user')." WHERE ".$contion,$params);
				$page = pagination($total,$pageindex,$psize);
				$total = $total - ($pageindex - 1)*$psize;
				if($_W['isajax']){
					$id = intval($_GPC['id']);
					$val = trim($_GPC['val']);
					if($val == '正常'){
						$data['status'] = 0;
						$res = pdo_update('goouc_class_user',$data,array('id'=>$id));
					}elseif($val == '禁用'){
						$data['status'] = 1;
						$res = pdo_update('goouc_class_user',$data,array('id'=>$id));
					}
					if($res){
						return json_encode(1);
					}else{
						return json_encode(0);
					}
				}
			}elseif($op == 'mystudy'){
			    $id = $_GPC['id'];
                $mylist = pdo_getall('goouc_class_stady',array('weid'=>$_W['uniacid'],'uid'=>$id));
                $array_less = array();
                foreach($mylist as $k => $v){
                    $b = pdo_fetch("SELECT l.id as lid,l.title as ltitle,l.image as limage,s.* FROM ".tablename('goouc_class_son')." s JOIN ".tablename('goouc_class_lesson')." l ON s.lessonid = l.id WHERE s.weid = :weid AND s.id = :id",array(':weid'=>$_W['uniacid'],':id'=>$v['sonid']));
                    $a = array('id'=>$b['lid'],'title'=>$b['ltitle'],'image'=>$b['image']);
                    unset($b['lid']);
                    unset($b['ltitle']);
                    unset($b['limage']);
                    if(!array_key_exists($a['id'],$array_less)){
                        $array_less[$a['id']] = $a;
                    }
                    $array_less[$a['id']]['son'][] = $b;
                }
            }
			include $this->template('web/user');
		}

		public function doWebBanner(){
			global $_W,$_GPC;
			$op = empty($_GPC['op'])?'list':$_GPC['op'];
			if($op == 'list'){
				$list = pdo_fetchall("SELECT * FROM ".tablename('goouc_class_banner')." WHERE weid = :weid  ORDER BY listorder,`position` DESC ",array(':weid'=>$_W['uniacid']));
			}elseif($op == 'post'){
				$classlist = pdo_getall('goouc_class_class',array('weid'=>$_W['uniacid'],'status'=>1));
				$id = intval($_GPC['id']);
				$info = pdo_get('goouc_class_banner',array('id'=>$id));
				if(checksubmit('token')){
					$data['weid'] = $_W['uniacid'];
					$data['title'] = $_GPC['title'];
					$data['status'] = $_GPC['status'];
					$data['image'] = $_GPC['image'];
					$data['type'] = $_GPC['type'];
					$data['link'] = $_GPC['link'];
					$data['position'] = $_GPC['position'];
					$data['listorder'] = $_GPC['listorder'];
					$data['createtime'] = time();
					$data['classid'] = $_GPC['classid'];
					if(empty($data['image'])){
						itoast('请选择图片','','error');
					}
					if(empty($id)){
						$res = pdo_insert('goouc_class_banner',$data);
						if($res){
							$arr = array(
								'weid'=>$_W['uniacid'],
								'admin_uid'=>$_W['uid'],
								'admin_username'=>$_W['username'],
								'log_type'=>1,
								'function'=>'轮播图管理->新增轮播图',
								'content'=>'新增轮播图'
							);
							$this->addlog($arr);
						}
					}else{
						$res = pdo_update('goouc_class_banner',$data,array('id'=>$id,'weid'=>$_W['uniacid']));
						if($res){
							$arr = array(
								'weid'=>$_W['uniacid'],
								'admin_uid'=>$_W['uid'],
								'admin_username'=>$_W['username'],
								'log_type'=>3,
								'function'=>'轮播图管理->修改轮播图',
								'content'=>'修改轮播图'
							);
							$this->addlog($arr);
						}
					}
					if($res){
						message('操作成功',$this->createWebUrl('banner'),'succss');
					}else{
						message('操作失败',$this->createWebUrl('banner'),'error');
					}
				}
			}elseif($op == 'delete'){
				$id = intval($_GPC['id']);
				$res = pdo_delete('goouc_class_banner',array('id'=>$id));
				if($res){
					$message = array('success'=>1,'mess'=>'删除成功');
					if($res){
						$arr = array(
							'weid'=>$_W['uniacid'],
							'admin_uid'=>$_W['uid'],
							'admin_username'=>$_W['username'],
							'log_type'=>2,
							'function'=>'轮播图管理->删除轮播图',
							'content'=>'删除轮播图'
						);
						$this->addlog($arr);
					}
				}else{
					$message = array('success'=>0,'mess'=>'删除失败');
				}
				echo json_encode($message);exit;
			}elseif($op == 'changestatus'){
				$id = $_GPC['id'];
				$data['status'] = $_GPC['sta'];
				$info = pdo_get('goouc_class_banner',array('id'=>$id,'weid'=>$_W['uniacid']));
				if($data['status'] == $info['status']){
					$message = array('success'=>0,'修改失败，请刷新页面后重新修改');
				}else{
					$res = pdo_update('goouc_class_banner',$data,array('id'=>$id,'weid'=>$_W['uniacid']));
					if($res){
						$message = array('success'=>1,'mess'=>'修改成功');
					}else{
						$message = array('success'=>0,'mess'=>'修改失败');
					}
				}
				echo json_encode($message);exit;
			}
			include $this->template('web/banner');
		}

		public function doWebPayment(){
		    global $_W,$_GPC;
		    $contion = " p.weid = :weid";
		    $params[':weid'] = $_W['uniacid'];
            $type = intval($_GPC['type']);
            if($type == 1 || $type == 2){
                $contion .= " AND type = :type";
                    $params[':type'] = $type;
            }
            $order_status = intval($_GPC['order_status']);
            if($order_status == 1 || $order_status == 2){
                $contion .= " AND order_status = :order_status";
                if($order_status == 1){
                    $params[':order_status'] = 1;
                }elseif($order_status == 2){
                    $params[':order_status'] = 0;
                }
            }
            if(!empty($_GPC['time'])){
                $starttime = strtotime($_GPC['time']['start']);
                $endtime = strtotime($_GPC['time']['end']) +86399;
                $contion .= " AND createtime >= :starttime AND createtime <= :endtime";
                $params[':starttime'] = $starttime;
                $params[':endtime'] = $endtime;
            }else{
                $starttime = strtotime('-1 month');
                $endtime = time();
            }
            $pindex = max(1,$_GPC['page']);
            $psize = 15;
		    $list = pdo_fetchall("SELECT p.type,p.userid,p.order_status,p.all_money,p.createtime,p.paytime,u.id as userid,u.nickname,u.headimg FROM ".tablename('goouc_os_order')." p JOIN ".tablename('goouc_class_user')." u ON p.userid = u.id WHERE ".$contion." ORDER BY createtime DESC LIMIT ".($pindex - 1)*$psize.",".$psize,$params);
		    $total = pdo_fetchcolumn("SELECT COUNT(*) FROM ".tablename('goouc_os_order')." p JOIN ".tablename('goouc_class_user')." u ON p.userid = u.id WHERE ".$contion,$params);
		    $page = pagination($total,$pindex,$psize);
		    $money = 0;
		    foreach($list as $v){
                if($v['order_status'] == 1){
                    $money += $v['all_money'];
                }
            }
		    include $this->template('web/payment');
        }
		

		public function addlog($arr){
			global $_W,$_GPC;
			$arr['ip'] = $_SERVER['REMOTE_ADDR'];
			$arr['addtime'] = time();
			return pdo_insert('goouc_class_syslog',$arr);
		}

		public function doWebSetting(){
			global $_W,$_GPC;
			$settings = $this->module['config'];
			if(checksubmit()){
				$data['regionId'] = empty($_GPC['regionId'])?'cn-shanghai':$_GPC['regionId'];
				$data['AccessKeyID'] = $_GPC['AccessKeyID'];
				$data['AccessKeySecret'] = $_GPC['AccessKeySecret'];
				$data['accessKeyId'] = $_GPC['accessKeyId'];
				$data['accessKeySecret'] = $_GPC['accessKeySecret'];
				$data['SignName'] = $_GPC['SignName'];
				$data['TemplateCode'] = $_GPC['TemplateCode'];
				$data['nstatus'] = empty($_GPC['nstatus'])?0:$_GPC['nstatus'];
				$data['cardprice'] = floatval($_GPC['cardprice']);
				if($_GPC['nstatus'] == 1){
					$data['nnum'] = empty($_GPC['nnum'])?1:$_GPC['nnum'];
				}else{
                    $data['nnum'] = 0;
                }
				$data['lstatus'] = empty($_GPC['lstatus'])?0:$_GPC['lstatus'];
				if($_GPC['lstatus'] == 1){
					$data['lnum'] = empty($_GPC['lnum'])?1:$_GPC['lnum'];
					$data['lday'] = empty($_GPC['lday'])?30:$_GPC['lday'];
					$data['ldnum'] = empty($_GPC['ldnum'])?1:$_GPC['ldnum'];
				}else{
                    $data['lnum'] = 0;
                    $data['lday'] = 0;
                    $data['ldnum'] = 0;
                }
				$data['sstatus'] = empty($_GPC['sstatus'])?0:$_GPC['sstatus'];
				if($_GPC['sstatus'] == 1){
					$data['snumber'] = empty($_GPC['snumber'])?1:$_GPC['snumber'];
					$data['snum'] = empty($_GPC['snum'])?1:$_GPC['snum'];
					$data['zsnum'] = empty($_GPC['zsnum'])?1:$_GPC['zsnum'];
				}else{
                    $data['snumber'] = 0;
                    $data['snum'] = 0;
                    $data['zsnum'] = 0;
                }
				$data['number'] = $_GPC['number'];
				$data['pay_status'] = $_GPC['pay_status'];
				if($data['pay_status'] == 1){
					$data['mchid'] = $_GPC['mchid'];
					$data['pay_secret'] = $_GPC['pay_secret'];
					if(empty($data['mchid']) || empty($data['pay_secret'])){
						message('开启支付后，商户信息以及支付秘钥不能为空','','error');
					}
					$data['pay_set'] = 1;
				}
				$res = $this->saveSettings($data);
				if($res){
					message('设置成功','','success');
				}else{
					message('设置失败','','error');
				}
			}
			include $this->template('settings');
		}

		public function updateCache($fname,$content = NULL){
			if(empty($content)){
				$content = $this->getsetting();
			}

			cache_delete($fname);

			cache_write($fname,$content);
		}

		public function doWebCard(){
			global $_W,$_GPC;
			$op = empty($_GPC['op'])?'list':$_GPC['op'];
			if($op == 'list'){
				$list = pdo_getall('goouc_class_cardinfo',array('weid'=>$_W['uniacid']));

			}elseif($op == 'post'){
				$id = $_GPC['id'];
				$info = pdo_get('goouc_class_cardinfo',array('weid'=>$_W['uniacid'],'id'=>$id));
				if(checksubmit('submit')){
					$data['weid'] = $_W['uniacid'];
					$data['cardnum'] = $_GPC['cardnum'];
					$data['price'] = empty($_GPC['price'])?'0.00':round($_GPC['price'],2);
					$data['status'] = $_GPC['status'];
					$data['order'] = $_GPC['order'];
					$data['createtime'] = time();
					if(empty($data['cardnum']) || $data['price'] == '0.00'){
						itoast('整包数量和价格不能为空','','error');
					}
					if(empty($id)){
						$res = pdo_insert('goouc_class_cardinfo',$data);
					}else{
						$res = pdo_update('goouc_class_cardinfo',$data,array('id'=>$id));
					}
					if($res){
						message('操作成功',$this->createWebUrl('card'),'success');
					}else{
						message('操作失败',$this->createWebUrl('card'),'error');
					}
				}
			}elseif($op == 'delete'){
				$id = $_GPC['id'];
				$res = pdo_delete('goouc_class_cardinfo',array('id'=>$id));
				if($res){
					message('删除成功',$this->createWebUrl('card'),'success');
				}else{
					message('删除失败',$this->createWebUrl('card'),'error');
				}
			}elseif($op == 'changestatus'){
				$id = $_GPC['id'];
				$data['status'] = $_GPC['sta'];
				$info = pdo_get('goouc_class_cardinfo',array('id'=>$id,'weid'=>$_W['uniacid']));
				if($data['status'] == $info['status']){
					$message = array('success'=>0,'修改失败，请刷新页面后重新修改');
				}else{
					$res = pdo_update('goouc_class_cardinfo',$data,array('id'=>$id,'weid'=>$_W['uniacid']));
					if($res){
						$message = array('success'=>1,'mess'=>'修改成功');
					}else{
						$message = array('success'=>0,'mess'=>'修改失败');
					}
				}
				echo json_encode($message);exit;
			}
			include $this->template('web/card');
		}

		// 海报分享设置
		public function doWebPoster(){
			global $_W,$_GPC;
			$op = empty($_GPC['op'])?'list':$_GPC['op'];
			if($op == 'info'){
				$type = $_GPC['type'];
				$position = $_GPC['position'];
				$pindex = max(1,intval($_GPC['page']));
				$psize = 5;
				$list = pdo_fetchall("SELECT * FROM ".tablename('goouc_class_poster')." WHERE weid=:weid AND `type`=:type AND `position`=:position order by position LIMIT ".($pindex - 1)*$psize.','.$psize,array(':weid'=>$_W['uniacid'],':type'=>$type,':position'=>$position));

				foreach($list as $k=>$v){
					if($v['position'] == 2){
						if($v['levelid'] == 0){
							$list[$k]['levelname'] = '学员';
						}else{
							$list[$k]['levelname'] = pdo_get('goouc_class_level',array('weid'=>$_W['uniacid'],'id'=>$v['levelid']))['name'];
						}
					}
				}
				$total = pdo_fetchcolumn("SELECT COUNT(*) FROM ".tablename('goouc_class_poster')." WHERE weid=:weid AND `type`=:type",array(':weid'=>$_W['uniacid'],':type'=>$type));
				$page = pagination($total,$pindex,$psize);
				$num = 1+($pindex-1)*$psize;
			}elseif($op == 'post'){
				$position = $_GPC['position'];
				$type = $_GPC['type'];
				$id = $_GPC['id'];
				if($position == 2){
					$levellist = pdo_getall('goouc_class_level',array('weid'=>$_W['uniacid']));
				}
				$info = pdo_get('goouc_class_poster',array('weid'=>$_W['uniacid'],'id'=>$id));
				if($info['position'] == 2){
					$levellist = pdo_getall('goouc_class_level',array('weid'=>$_W['uniacid']));
				}
				if(checksubmit('submit')){
					$data['weid'] = $_W['uniacid'];
					$data['title'] = $_GPC['title'];
					$data['image'] = $_GPC['image'];
					$data['order'] = $_GPC['order'];
					$data['status'] = $_GPC['status'];
					$data['position'] = $_GPC['position'];
					$data['type'] = $_GPC['type'];
					$data['createtime'] = time();
					if($data['position'] == 2){
						$data['levelid'] = $_GPC['levelid'];
					}
					if(empty($data['title']) || empty($data['image'])){
						message('标题或图片不能为空','','error');
					}
					if(empty($id)){
						$res = pdo_insert('goouc_class_poster',$data);
						if($res){
							$arr = array(
								'weid'=>$_W['uniacid'],
								'admin_uid'=>$_W['uid'],
								'admin_username'=>$_W['username'],
								'log_type'=>1,
								'function'=>'海报设置->海报设置',
								'content'=>'新增海报背景'
							);
							$this->addlog($arr);
						}
					}else{
						$res = pdo_update('goouc_class_poster',$data,array('id'=>$id));
						if($res){
							$arr = array(
								'weid'=>$_W['uniacid'],
								'admin_uid'=>$_W['uid'],
								'admin_username'=>$_W['username'],
								'log_type'=>3,
								'function'=>'海报设置->海报设置',
								'content'=>'更改海报信息'
							);
							$this->addlog($arr);
						}
					}
					if($res){
						message('操作成功',$this->createWebUrl('poster'),'success');
					}else{
						message('操作失败',$this->createWebUrl('poster'),'error');
					}

				}
			}elseif($op == 'delete'){
				$id = $_GPC['id'];
				$res = pdo_delete('goouc_class_poster',array('id'=>$id));
				if($res){
					message('删除成功',$this->createWebUrl('card'),'success');
				}else{
					message('删除失败',$this->createWebUrl('card'),'error');
				}
			}elseif($op == 'changestatus'){
				$id = $_GPC['id'];
				$data['status'] = $_GPC['sta'];
				$info = pdo_get('goouc_class_poster',array('id'=>$id,'weid'=>$_W['uniacid']));
				if($data['status'] == $info['status']){
					$message = array('success'=>0,'修改失败，请刷新页面后重新修改');
				}else{
					$res = pdo_update('goouc_class_poster',$data,array('id'=>$id,'weid'=>$_W['uniacid']));
					if($res){
						$message = array('success'=>1,'mess'=>'修改成功');
					}else{
						$message = array('success'=>0,'mess'=>'修改失败');
					}
				}
				echo json_encode($message);exit;
			}elseif($op == 'list'){
				$list1 = pdo_getall('goouc_class_type_status',array('weid'=>$_W['uniacid'],'position'=>1));
				$list2 = pdo_getall('goouc_class_type_status',array('weid'=>$_W['uniacid'],'position'=>2));
			}elseif($op == 's2'){
				for($i = 0;$i <= 5;$i++ ){
					$data2 = array('weid'=>$_W['uniacid'],'name'=>'模板'.($i+1),'type'=>($i+1),'status'=>0,'position'=>2,'image'=>'images/signin_qrcode/'.($i+1).'.jpg');
					pdo_insert('goouc_class_type_status',$data2);
				}
				message('生成成功',$this->createWebUrl('poster'),'success');
			}elseif($op == 's1'){
				for($i = 0;$i <= 5;$i++ ){
					$data1 = array('weid'=>$_W['uniacid'],'name'=>'模板'.($i+1),'type'=>($i+1),'status'=>0,'position'=>1,'image'=>'images/lesson_qrcode/'.($i+1).'.jpg');
					pdo_insert('goouc_class_type_status',$data1);
				}
				message('生成成功',$this->createWebUrl('poster'),'success');
			}elseif($op == 'type_status'){
				$id = $_GPC['id'];
				$data['status'] = $_GPC['sta'];
				$info = pdo_get('goouc_class_type_status',array('id'=>$id,'weid'=>$_W['uniacid']));
				if($data['status'] == $info['status']){
					$message = array('success'=>0,'修改失败，请刷新页面后重新修改');
				}else{
					$res = pdo_update('goouc_class_type_status',$data,array('id'=>$id,'weid'=>$_W['uniacid']));
					if($res){
						$message = array('success'=>1,'mess'=>'修改成功');
					}else{
						$message = array('success'=>0,'mess'=>'修改失败');
					}
				}
				echo json_encode($message);exit;
			}
			include $this->template('web/poster');
		}

		//开启curl get请求 
	    public function curl_get($url) {
	        $curl = curl_init();
	        curl_setopt($curl, CURLOPT_URL, $url);
	        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
	        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	        $data = curl_exec($curl);
	        $err = curl_error($curl);
	        curl_close($curl);
	        return $data;
	    }
	    //开启curl post请求
	    public function get_http_array($url,$post_data) {
	        $ch = curl_init();
	        curl_setopt($ch, CURLOPT_URL, $url);
	        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
	        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);   //没有这个会自动输出，不用print_r();也会在后面多个1
	        curl_setopt($ch, CURLOPT_POST, 1);
	        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
	        $output = curl_exec($ch);
	        return $output;
	    }
		
	}
?>